<?php
/**
 * 通用页头文件
 */

if (!defined('ROOT_PATH')) {
    die('直接访问被禁止');
}

// 获取当前页面
$current_page = get_current_page();
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo get_page_title(); ?></title>
    <link rel="stylesheet" href="<?php echo asset_url('css/bootstrap.min.css'); ?>">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    <link rel="stylesheet" href="<?php echo asset_url('css/styles.css?v=1.1'); ?>">
    <?php 
    // 如果页面有额外的CSS和JS，可以在此显示
    if (isset($page_styles) && !empty($page_styles)) {
        echo $page_styles;
    }
    ?>
</head>
<body>
    <div class="container-fluid">
        <!-- 导航栏 -->
        <nav class="navbar navbar-expand-lg navbar-light">
            <div class="container">
                <a class="navbar-brand" href="<?php echo page_url('index'); ?>"><i class="bi bi-brightness-high"></i>KidsMind</a>
                <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="collapse navbar-collapse" id="navbarNav">
                    <ul class="navbar-nav me-auto">
                        <li class="nav-item <?php echo ($current_page == 'index') ? 'active' : ''; ?> mx-2">
                            <a class="nav-link <?php echo ($current_page == 'index') ? 'active' : ''; ?>" href="<?php echo page_url('index'); ?>"><i class="bi bi-house-door"></i> 首页</a>
                        </li>
                        <li class="nav-item dropdown <?php echo (in_array($current_page, ['age-3-4', 'age-5-6', 'age-7-8'])) ? 'active' : ''; ?> mx-2">
                            <a class="nav-link dropdown-toggle <?php echo (in_array($current_page, ['age-3-4', 'age-5-6', 'age-7-8'])) ? 'active' : ''; ?>" href="#" id="answerAreaDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                                <i class="bi bi-journal-check"></i> 答题专区
                            </a>
                            <ul class="dropdown-menu" aria-labelledby="answerAreaDropdown">
                                <li><a class="dropdown-item <?php echo ($current_page == 'age-3-4') ? 'active' : ''; ?>" href="<?php echo page_url('age-3-4'); ?>"><i class="bi bi-emoji-smile"></i> 3-4岁专区</a></li>
                                <li><a class="dropdown-item <?php echo ($current_page == 'age-5-6') ? 'active' : ''; ?>" href="<?php echo page_url('age-5-6'); ?>"><i class="bi bi-emoji-wink"></i> 5-6岁专区</a></li>
                                <li><a class="dropdown-item <?php echo ($current_page == 'age-7-8') ? 'active' : ''; ?>" href="<?php echo page_url('age-7-8'); ?>"><i class="bi bi-emoji-sunglasses"></i> 7-8岁专区</a></li>
                            </ul>
                        </li>
                        <li class="nav-item <?php echo ($current_page == 'achievements') ? 'active' : ''; ?> mx-2">
                            <a class="nav-link <?php echo ($current_page == 'achievements') ? 'active' : ''; ?>" href="<?php echo page_url('achievements'); ?>"><i class="bi bi-trophy"></i> 我的成就</a>
                        </li>
                    </ul>
                    <div class="auth-buttons d-flex">
                        <?php if (is_logged_in()): ?>
                            <div class="me-3">
                                <span class="badge bg-warning">⭐ <?php echo isset($_SESSION['user_points']) ? $_SESSION['user_points'] : '0'; ?></span>
                            </div>
                            <a href="<?php echo page_url('profile'); ?>" class="btn btn-outline-light me-2"><i class="bi bi-person"></i> 我的账户</a>
                            <a href="<?php echo page_url('logout'); ?>" class="btn btn-light"><i class="bi bi-box-arrow-right"></i> 退出</a>
                        <?php else: ?>
                            <a href="<?php echo page_url('login'); ?>" class="btn btn-outline-light me-2"><i class="bi bi-box-arrow-in-right"></i> 登录</a>
                            <a href="<?php echo page_url('register'); ?>" class="btn btn-light"><i class="bi bi-person-plus"></i> 注册</a>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </nav>

        <!-- 主内容区开始 --> 